package com.jason.www.controller.vo;

import lombok.Data;

import java.util.Map;

import static com.jason.www.enums.PayType.NEWALIPAY;
import static com.jason.www.enums.PayType.UNIONPAY;
import static com.jason.www.enums.PayType.WXPAY;


@Data
public class PayCallbackVo {
	/**
	 * 订单号
	 */
	private String payNo;
	/**
	 * 流水号
	 */
	private String tradeNo;
	private Byte payType;
	private String totalFee;

	public static PayCallbackVo buildAlipayCallback(Map<String, String> params) {
		PayCallbackVo payCallbackVo = new PayCallbackVo();
		payCallbackVo.setPayNo(params.get("out_trade_no"));
		payCallbackVo.setTradeNo(params.get("trade_no"));
		payCallbackVo.setTotalFee(params.get("total_amount"));
		payCallbackVo.setPayType(NEWALIPAY.getCode());
		return payCallbackVo;
	}

	public static PayCallbackVo buildUnionpayCallback(Map<String, String> params) {
		PayCallbackVo payCallbackVo = new PayCallbackVo();
		payCallbackVo.setPayNo(params.get("orderId"));
		payCallbackVo.setTradeNo(params.get("queryId"));
		payCallbackVo.setTotalFee(params.get("txnAmt"));
		payCallbackVo.setPayType(UNIONPAY.getCode());
		return payCallbackVo;
	}

    public static PayCallbackVo buildWXpayCallback(Map<String, String> params) {
		PayCallbackVo payCallbackVo = new PayCallbackVo();
		payCallbackVo.setPayNo(params.get("out_trade_no"));
		payCallbackVo.setTradeNo(params.get("transaction_id"));
		payCallbackVo.setTotalFee(params.get("total_fee"));
		payCallbackVo.setPayType(WXPAY.getCode());
		return payCallbackVo;
    }
}
